package org.example.queue;

/**
 * @author liyishan
 * @date 2024/10/9 16:17
 * @apiNote
 */

public class QueueByLink {
    Node front;
    Node tail;
    int size;
    public boolean isEmpty(){
        return size == 0;
    }
    public void offer(int data){
        Node temp = new Node(data);
        if(isEmpty()){
            front = temp;
            tail = temp;
        }else{
            tail.next = temp;
            tail = tail.next;
        }
        size++;
    }

    public int poll(){
        if(isEmpty()){
            throw new RuntimeException("Queue is empty");
        }
        int data = front.data;
        front = front.next;
        size--;
        return data;
    }

    private static class Node{
        public int data;
        public Node next;
        public Node (int data){
            this.data = data;
        }
    }

}
